from typing import Any

from aiogram import F, types
from aiogram_dialog import DialogManager, Window
from aiogram_dialog.widgets.kbd import Back, Button, Cancel, Group

from app.bot.dialog.dialog_states import SelectProxySG
from app.bot.dialog.widgets import LocaleText


async def set_proxy_period(
    call: types.CallbackQuery, widget: Any, manager: DialogManager
):

    manager.dialog_data["period"] = widget.widget_id
    await manager.switch_to(SelectProxySG.set_order_quantity)


async def back_to_provider(
    call: types.CallbackQuery, widget: Any, manager: DialogManager
):
    await manager.switch_to(SelectProxySG.list_of_providers)


period_window = Window(
    LocaleText("select-period"),
    Group(
        Button(LocaleText("four_hours"), id="four_hours", on_click=set_proxy_period),
        Button(LocaleText("one_day"), id="one_day", on_click=set_proxy_period),
        Button(LocaleText("one_week"), id="one_week", on_click=set_proxy_period),
        Button(LocaleText("two_weeks"), id="two_weeks", on_click=set_proxy_period),
        Button(LocaleText("one_month"), id="one_month", on_click=set_proxy_period),
        width=2,
    ),
    Back(LocaleText("back-btn"), when=F["dialog_data"]["proxy_privacy"] != "private"),
    Button(
        LocaleText("back-btn"),
        when=F["dialog_data"]["proxy_privacy"] == "private",
        id="back_btn",
        on_click=back_to_provider,
    ),
    Cancel(LocaleText("cancel-btn")),
    state=SelectProxySG.select_period,
)
